package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.config.fishpond.FishPondBadgeConfig;
import com.yanqu.road.entity.config.fishpond.FishPondItemConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author ：zfr
 * @date ：2021/10/18 14:41
 */
public class FishPondConfigDaoImpl extends TempDao {


    public Map<Integer, FishPondItemConfig> getFishPondItemConfigMap() {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, FishPondItemConfig> dataMap = new ConcurrentHashMap<>();
        String sql = "select * from t_p_fishpond_item";
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                FishPondItemConfig data = new FishPondItemConfig();
                data.setId(rs.getInt("id"));
                data.setType(rs.getInt("type"));
                data.setQuality(rs.getInt("quality"));
                data.setSkills(rs.getString("skills"));
                data.setWeight(rs.getString("weight"));
                data.setWeather(rs.getInt("weather"));
                data.setTime(rs.getInt("time"));
                data.setFisherPoints(rs.getInt("fisherPoints"));
                data.setExp(rs.getInt("exp"));
                data.setRewardList(rs.getString("rewardList"));
                data.setFishCondition(rs.getString("fishCondition"));
                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

    public Map<Integer, FishPondBadgeConfig> getFishPondBadgeConfigMap() {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, FishPondBadgeConfig> dataMap = new ConcurrentHashMap<>();
        String sql = "select * from t_p_fishpond_badge";
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                FishPondBadgeConfig data = new FishPondBadgeConfig();
                data.setId(rs.getInt("id"));
                data.setNeedFisherPoints(rs.getInt("needFisherPoints"));
                data.setSkillsList(rs.getString("skillsList"));
                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
}
